import request from '../utils/request';
import useSwr from 'swr';
import { UserProfile } from '../store';

// API 函数
export async function getUserProfile() {
  const { data } = await request.get<UserProfile>('/user/profile');
  return data;
}

// SWR Hooks
export default function useUserProfile() {
  const { data, error, isLoading, mutate } = useSwr('/user/profile', () => getUserProfile());

  return {
    profile: data,
    error,
    isLoading,
    mutate,
  };
}
